<?php
define("ROOT_PATH", "");
#--------------------------------------------------
# ALL INCLUDES + STANDARD-VALUES
#--------------------------------------------------
include_once ("include/config.inc");
include_once ("include/template.inc");
include_once ("include/class.db.php5");
include_once ("include/class.tools.php5");
include_once ("include/class.time.php5");
include_once ("member/tools.php5");
include_once ("dataAccess/classes/Image.php5");
include_once ("dataAccess/dao/ImageDAO.php5");
$svo = new db("svoptik");
$tools = new tool();
$time = new TimeUtil();

include_once ("include/global_fix_extern.inc");

#--------------------------------------------------
# CREATE TEMPLATE
#--------------------------------------------------
$t = new Template("templates", "keep");
$t->set_file(array (
	"page" => "svoptik.tpl",
	"navi" => "navi.tpl",
	"ticker" => "ticker.tpl",
	"link" => "links.tpl",
	"gallery" => "galleries.tpl",
	"img_overview" => "gallery_images.tpl",
	"image" => "image.tpl"
));
#--------------------------------------------------
$t->set_var(array (
	"FORWARD" => ""
));

#--------------------------------------------------
# CREATE NAVIGATION RIGHT
#--------------------------------------------------
$links = "";
$url[0] = array (
	"URL" => "",
	"URL-TEXT" => "",
	"ONCLICK" => "",
	"TARGET" => "_self"
);
for ($i = 0; $i < count($url); $i++) {
	$links .= "
	        <tr height=\"15\">
				<td valign=\"top\"><img src=\"standard/spacer.gif\" width=\"20\" height=\"15\" border=\"0\" alt=\"\"></td>
				<td valign=\"top\"><a href=\"" . $url[$i]['URL'] . "\" class=\"sitenav\" target=\"" . $url[$i]['TARGET'] . "\" onClick=\"" . $url[$i]['ONCLICK'] . "\">" . $url[$i]['URL-TEXT'] . "</a></td>
				<td valign=\"top\"><img src=\"standard/spacer.gif\" width=\"20\" height=\"15\" border=\"0\" alt=\"\"></td>
			</tr>
			<tr height=\"15\">
	            <td colspan=\"3\"><img src=\"standard/spacer.gif\" width=\"20\" height=\"15\" border=\"0\" alt=\"\"></td>
			</tr>
	       ";
}
$t->set_var(array (
	"LINKS" => $links,
	"BANNER" => $banner
));
$right_nav = $t->parse("", "navi", true);
#--------------------------------------------------

#--------------------------------------------------
# CREATE ALL-TIME SAME THINGS
#--------------------------------------------------
include_once ("include/sameThings.php5");

#--------------------------------------------------

#--------------------------------------------------
# CREATE CONTENT "Gallery"
#--------------------------------------------------

$dao = new ImageDAO();

if (isset($_REQUEST["action"])){
	$action = $_REQUEST["action"];
} else {
	$action = "ALL";
}

if ($action == "ALL") {
	$sitenav = "<a href=\"gallery.php5\" class=\"sitenav\">BILDER</a> -> &Uuml;BERSICHT";
	$galleries = $dao->findAllGalleriesGUI();

	$dscroll = dataScroller(count($galleries), 5, "start");

	if (count($galleries) > 0) {
		for ($i = ($dscroll["from"] - 1); $i < $dscroll["to"]; $i++){
			$gallery = $galleries[$i];
			$foto = $gallery->startImage;
			if ($foto > 0){
				$foto = sprintf("<img src=\"%s\" border=\"0\"/>", SPONSOR_IMG_DIR.$foto);
			} else {
				$foto = "Not Set";
			}
			if ($gallery->dateFirstPersist != $gallery->dateLastPersist){
				$edited = "(Aktualisiert)";
			} else {
				$edited = "";
			}
			$t->set_var(array (
				"ID" => $tools->html_replace($gallery->id), 
				"TITLE" => $tools->html_replace($gallery->title), 
				"DESCRIPTION" => $tools->html_replace($gallery->description), 
				"LOCATION" => $tools->html_replace($gallery->location), 
				"PERSIST" => date("d.m.Y", strtotime($gallery->dateFirstPersist)), 
				"EDITED" => $edited, 
				"FOTO" => $foto));
			$content .= $t->parse("", "gallery", true);
		}

		// dataScroller Daten erzeugen
		include_once ("member/includes/dataScroller.php5");
	}
}


if ($action == "GALLERY") {

	if (isset($_REQUEST["id"])){
		$id = $_REQUEST["id"];
	} else {
		$id = 0;
	}
	$galleryDir = "images/gallery/".$id."/";
	// gallery laden
	$gallery = $dao->findGalleryById($id);

	$sitenav = "<a href=\"gallery.php5\" class=\"sitenav\">BILDER</a> -> ".$gallery->title;
	
	// bilder laden
	$images = $dao->findImagesByGallery($id);

	$dscroll = dataScroller(count($images), 20, "start");
	
	$requestVars="&action=GALLERY&id=".$id;
	
	$i = 0;
	foreach ($images as $image) {
		if ($i >= ($dscroll["from"] - 1) && $i < $dscroll["to"]){
			$style = "display:block;";
		} else {
			$style = "display:none;";
		}
		$t->set_var(array (
			"STYLE" => $style,
			"GALLERY_TITLE" => $gallery->title,
			"GALLERY_LOC" => $gallery->location,
			"GALLERY_DESC" => $gallery->description,
			"IMAGE_URL" => $galleryDir.$image->fileName,
			"THUMB_URL" => $galleryDir."th/".$image->thumbName,
			"GALLERY_ID" => $id,
			"SUBTITLE" => $image->subtitle,
			"IMG_NUM" => $i
		));
		$imagesHTML .= $t->parse("", "image", true);
		$i++;
	}
	$t->set_var(array (
			"IMAGES" => $imagesHTML
	));
	$content .= $t->parse("", "img_overview", true);
	
	// dataScroller Daten erzeugen
	include_once ("member/includes/dataScroller.php5");
}
#--------------------------------------------------

#--------------------------------------------------
# PARSE & OUTPUT
#--------------------------------------------------
$t->set_var(array (
	"sitenav" => $sitenav,
	"ticker" => $ticker,
	"content" => $content . "<br>",
	"navi" => $right_nav,
	"SYNCHRONIZE" => " "
	));

	$t->parse("ALL", "page", true);
	$t->p("ALL");
	?>
